package com.zlzxm.sorting.ui.window;

import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

import com.zlzxm.sorting.R;


/**
 * CREATE BY zlzxm ON 2021/10/22
 */
public class LoadingWindow extends DialogFragment {

    public static LoadingWindow getInstance() {
        return new LoadingWindow();
    }
    public static LoadingWindow show(FragmentManager fragmentManager) {
        LoadingWindow loadingWindow =  getInstance();
        loadingWindow.show(fragmentManager,"loading");
        return loadingWindow;
    }

    private LoadingWindow() {
    }

    private String tip;

    public LoadingWindow setTip(String tip) {
        this.tip = tip;
        if(tvTip!=null){

            tvTip.setText(tip);
        }
        return  this;
    }


    private TextView tvTip;

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

        Dialog dialog = new Dialog(getContext());

        dialog.setContentView(R.layout.window_loading);

        Window window = dialog.getWindow();
        window.setBackgroundDrawable(new ColorDrawable(0));

        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        tvTip =  dialog.findViewById(R.id.tvTip);

        if(TextUtils.isEmpty(tip)){

            tvTip.setVisibility(View.GONE);

        }else {

            tvTip.setVisibility(View.VISIBLE);
            tvTip.setText(tip);
        }

        return dialog;
    }


}
